<template>
  <bfs-order-std :field-options="fieldOption" :line-field-options="fieldOptionLine" ref="orderRef">
    <template v-slot:btn="prop">
      <q-btn @click="onUpdateContractno" color="primary" label="更新合同号" v-if="prop.data.orderType === 1 && prop.data.detailStatus.isViewMode"/>
    </template>
  </bfs-order-std>
</template>

<script lang="ts">
export default {
  name: 'Order'
}
</script>

<script lang="ts" setup>

import {FieldOptionsDef} from '@njt/bfs/defs/comm'
import {ref} from 'vue'

const fieldOption: FieldOptionsDef = {
  userDef1: {
    isShown: true
  },
  userDef2: {
    isShown: true
  },
  userDef3: {
    isShown: true
  },
  userDef4: {
    isShown: true
  },
  userDef5: {
    isShown: true
  },
  userDef6: {
    isShown: true
  },
  userDef7: {
    isShown: true
  },
  userDef8: {
    isShown: true
  },
  userDef9: {
    isShown: true
  },
  userDef10: {
    isShown: true
  },
  userDef11: {
    isShown: true
  },
  userDef12: {
    isShown: true
  },
  userDef13: {
    isShown: true
  },
  userDef14: {
    isShown: true
  },
  userDef15: {
    isShown: true
  }
}

const fieldOptionLine: FieldOptionsDef = {
  userDef1: {
    isShown: true,
    label: '是否加急'
  },
  userDef2: {
    isShown: true,
    label: '实际入库日期'
  },
  userDef3: {
    isShown: true,
    label: '期待完成日期'
  },
  userDef4: {
    isShown: true
  },
  userDef5: {
    isShown: true
  },
  userDef6: {
    isShown: true
  },
  userDef7: {
    isShown: true
  },
  userDef8: {
    isShown: true
  },
  userDef9: {
    isShown: true,
    label: '商品序号'
  },
  userDef10: {
    isShown: true
  },
  userDef11: {
    isShown: true
  },
  userDef12: {
    isShown: true
  },
  userDef13: {
    isShown: true
  },
  userDef14: {
    isShown: true
  },
  userDef15: {
    isShown: true,
    label: '证书号'
  }
}

let orderRef = ref<any>()
const onUpdateContractno = () => {
  void $f.ui.messageBox({
    caption: '操作确认',
    text: '确认更新合同号吗?',
    icon: 'Warning',
    buttons: 'OkCancel',
    delayClose: true
  }).then((btn) => {
    if (btn === 'ok') {
      $f.axios
          .post('/project/mhlbc/work/order/update-contractno-for-wms', [orderRef.value.itemId])
          .then(() => {
            $f.ui.closeMsgBox()
            orderRef.value.loadModelData()
          })
          .catch((err) => {
            void $f.ui.messageBox({
              caption: '更新合同号失败',
              text: $f.getAxiosErrMsg(err),
              icon: $f.getAxiosErrIcon(err),
              buttons: 'Close'
            })
          })
    }
  })
}

</script>

<style scoped>

</style>
